#pragma once
#include <string>
#include<Thread/SafeQueue.hpp>


#define GLOG_ENABLE

class GLog
{
public:
    enum class LogType
    {
        None = 0,
        Debug,
        Trace,
        Info,
        Warn,
        Error
    };
private: 
#ifdef GLOG_ENABLE 
    static std::thread logThread;
    struct LogStruct
    {
        GLog::LogType type;
        std::string log;
    };

   static SafeQueue<LogStruct> logQueue;
   static void LogthreadMain();
#endif
public:

    static void Log(const std::string log,const std::string& file, int line,enum LogType type = LogType::None); ;
    // static void Log_printf(const std::string& file,enum LogType type, int line,const char * Formt, ...);
    
};

#define LOG(log) GLog::Log(log, __FILE__, __LINE__,GLog::LogType::None)
#define ConditionLog(condition, log) if(condition) LOG(log) 
#define DEBUG(log) GLog::Log(log, __FILE__, __LINE__, GLog::LogType::Debug)
#define TRACE(log) LOG(std::string("TRACE::线程ID ")+std::to_string(this_thread::get_id())+"::" + log)
#define INFO(log) GLog::Log(log, __FILE__, __LINE__, GLog::LogType::Info)
#define WARN(log) GLog::Log(log, __FILE__, __LINE__, GLog::LogType::Warn)
#define ERROR(log) GLog::Log(log, __FILE__, __LINE__, GLog::LogType::Error)
#ifdef GLOG_ENABLE 
#define ExecutionTimeLog(fun,log)       {\
                    auto start = std::chrono::high_resolution_clock::now();\
                    fun();\
                    auto end = std::chrono::high_resolution_clock::now();\
                    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);\
                    LOG(log+" 执行时间: " + std::to_string(duration.count()) + " ms");\
                }
#else
#define ExecutionTimeLog(fun,log) fun()
#endif
// #define LOG_PRINT(fmt, ...) GLog::Log_printf( __FILE__, __LINE__,fmt, __VA_ARGS__) 
// #define DEBUG_PRINT(fmt, ...) LOG_PRINT
